use rand::Rng;
use std::cmp::*;
use std::io::*;

pub fn start_guess() {
    let rng: i32 = rand::thread_rng().gen_range(1..=100);
    loop {
        println!("请输入一个整数: ");
        // 创建一个新的随机数生成器实例（基于系统时间作为种子）
        let mut input = String::new();
        stdin().read_line(&mut input).expect("读取输入时出错");
        let num: i32 = input.trim().parse().expect("输入字符转换为数字发生错误"); 
        
        match num.cmp(&rng) {
            Ordering::Greater => {
                println!("太大了");
            }
            Ordering::Less => {
                println!("太小了");
            }
            Ordering::Equal => {
                println!("答对了");
                break;
            }
        }
    }
}
